package com.taotao.controller;

import com.taotao.bean.TbContent;
import com.taotao.bean.TbContentCategory;
import com.taotao.service.ContentService;
import com.taotao.utils.TaotaoResult;
import com.taotao.vo.LayuiEditResult;
import com.taotao.vo.LayuiTableResult;
import com.taotao.vo.ZtreeResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController
@RequestMapping("/content")
public class ContentController {
    @Autowired
    private ContentService contentService;

    @RequestMapping("/showContentCategory")
    public List<ZtreeResult> showContentCategory(@RequestParam(value = "id",defaultValue = "0") Long parentId){
        List<ZtreeResult> results = contentService.findContentCategoryByParentId(parentId);
        return results;
    }
    @RequestMapping("/updateContentCategory")
    public TaotaoResult updateContentCategory(@RequestBody TbContentCategory tbContentCategory){
        TaotaoResult result = contentService.updateContentCategory(tbContentCategory);
        return result;
    }
    @RequestMapping("/deleteContentCategory")
    public TaotaoResult deleteContentCategory(@RequestBody TbContentCategory tbContentCategory){
        TaotaoResult result = contentService.deleteContentCategory(tbContentCategory);
        return result;
    }
    @RequestMapping("/addContentCategory")
    public TaotaoResult addContentCategory(@RequestBody TbContentCategory tbContentCategory){
        TaotaoResult result = contentService.addContentCategory(tbContentCategory);
        return result;
    }
    @RequestMapping("/findContentByCId")
    public LayuiTableResult findContentByCId(Long categoryId){
        LayuiTableResult result = contentService.findContentByCId(categoryId);
        return result;
    }
    @RequestMapping("/showContent")
    public LayuiTableResult showContent(Long categoryId,Integer limit,Integer page){
        LayuiTableResult result = contentService.findContentByCategoryId(categoryId,limit,page);
        return result;
    }
    @RequestMapping("/delContent")
    public TaotaoResult deleteContent(@RequestBody List<TbContent> tbContents){
        TaotaoResult result = contentService.deleteContent(tbContents);
        return result;
    }

    /**
     * 这个接口返回的json格式 他既满足了普通图片上传也满足了
     * 富文本编辑框的
     * @param file
     * @return
     */
    @RequestMapping("/addPic")
    public LayuiEditResult addPic(MultipartFile file){
        LayuiEditResult result = contentService.addPic(file);
        return result;
    }
    @RequestMapping("/addContent")
    public TaotaoResult addContent(@RequestBody TbContent tbContent){
        TaotaoResult result = contentService.addContent(tbContent);
        return result;
    }
}
